<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        
        function sum(a,b)
        { 
            //先反转位数对齐
            a = a.split('').reverse();
            b = b.split('').reverse();
            let result = [];
            let maxLen = Math.max(a.length,b.length);
            let carry = 0;
            for(let i = 0;i<maxLen;i++)
            {
                  let sum = 0;
                  sum+=carry;
                  if(a.length>i)
                  {
                     sum+=parseInt(a[i]);
                  }
                  if(b.length>i)
                  {
                    sum+=parseInt(b[i]);
                  }

                result.push(sum%10);
                carry = Math.floor(sum/=10);
            }

            return result.reverse().join('');
        }

        let a = '123';
        let b = '123';
        console.log(sum(a,b));
        
    </script>
</body>
</html>